﻿using Prism.Commands;
using Prism.Common;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using WheelClean2.Model;
using WheelClean2.Mould;

namespace WheelClean.ViewModels
{
    class AlarmDialogViewModel : BindableBase, IDialogAware
    {
        private readonly IRegionManager _regionManager;
        private readonly IDialogService _dialog;
        private ObservableCollection<CurrentAlarm> _infos;

        public event Action<IDialogResult> RequestClose;

        /// <summary>
        /// 主题列表
        /// </summary>
        public ObservableCollection<CurrentAlarm> Infos
        {
            get { return _infos; }
            set { SetProperty(ref _infos, value); }
        }

        public DelegateCommand<string> DelegateCommand_Open { get; private set; }

        public string Title => "警报列表";

        AlarmDialogViewModel(IRegionManager contentRegion, IDialogService dialog)
        {
            _regionManager = contentRegion;
            _dialog = dialog;
            Infos = new ObservableCollection<CurrentAlarm>();
            //获取主体信息
            using (var db = new AppDbContext())
            {
                var list = db.CurrentAlarms.ToList();
                list.ForEach(t =>
                {
                    t.AlarmInfo = db.AlarmInfos.FirstOrDefault(f => f.AlarmID == t.AlarmID);
                });
                Infos.AddRange(list);
            }
        

        }

 

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
          
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
           
        }
    }
}
